<?php

class StockExchange
{
	private $_rate;
	private $_available;
	const SELL_RATE=0.92;
	public function __construct()
	{
		$this->_rate=10000;
		$this->_available=100;
	}
	public function buy($amount)
	{
		$price=$this->_rate*$amount;
		$this->_rate=round($this->_rate*$this->_available/($this->_available-$amount));
		$this->_available-=$amount;
		return $price;
	}
	public function sell($amount)
	{
		$price=round($this->_rate*$amount*self::SELL_RATE);
		$this->_rate=round($this->_rate*$this->_available/($this->_available+$amount));
		$this->_available+=$amount;
		return $price;
	}
	public function __toString()
	{
		return "Árfolyam: {$this->_rate}/".round($this->_rate*self::SELL_RATE).", Van még: $this->_available <br />";
	}
}

echo "<pre>";
$money=100000;
$stock=new StockExchange();
echo $stock;
$money-=$stock->buy(3);
echo $stock;
$money-=$stock->buy(3);
echo $stock;
$stock->buy(30);
$money+=$stock->sell(3);
echo $stock;
$money+=$stock->sell(3);
echo $stock;
echo $money/1000;

require_once("core/Request.php");
Request::init();